//
//  AponeBtn.swift
//  民生生活
//
//  Created by apple on 2017/8/7.
//  Copyright © 2017年 youjindi.app.com. All rights reserved.
//

import UIKit
import ReactiveCocoa
import ReactiveSwift
import Result

class AponeBtn: UIView {

    let titleLabel = UILabel()
    let imageView = UIImageView()
    
    init(_ title: String,_ image: String,_ frame: CGRect,_ command: Action<Void, Void, NoError>) {
        super.init(frame: frame)
        setView(title,image,command)
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
     
    private func setView(_ title: String,_ image: String,_ command: Action<Void, Void, NoError>) -> Void{
        imageView.image = UIImage(named:image)
        imageView.contentMode = .scaleToFill
        imageView.frame = CGRect(x: frame.width/2 - 16.5, y: 8, width: 33, height: 33)
        self.addSubview(imageView)
        
        titleLabel.frame = CGRect(x: 0, y: imageView.frame.maxY + 8, width: frame.size.width, height: 23)
        titleLabel.backgroundColor = UIColor.white
        titleLabel.text = title
        titleLabel.textAlignment = .center
        titleLabel.font = UIFont.systemFont(ofSize: 12)
        self.addSubview(titleLabel)
        
        let btn = UIButton(frame: self.bounds)
        btn.reactive.controlEvents(.touchUpInside).observeValues { (btn) in
            command.apply().start()
        }
        self.addSubview(btn)
        
    }
    

}
